<?php

declare(strict_types = 1);
namespace app\common\middleware;
class Cross{
    public function handle($request, \Closure $next)
    {
        $response = $next($request);
        $origin= $request->header('Origin', '*');
        if ($request->method(true) === 'OPTIONS') {
            $response->code(204);
        }
        $response->header([
            'Access-Control-Allow-Origin'      => '*',
            'Access-Control-Allow-Methods'     => 'GET, POST, PUT,DELETE,OPTIONS,PATCH',
            'Access-Control-Allow-Credentials' => 'true',
            'Access-Control-Allow-Headers'     => '*',
        ]);
        return $response;
    }
}